home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / checkbox / registries / gconf.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  3KB  |  106 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import re
  5. import posixpath
  6. from checkbox.lib.cache import cache
  7. from checkbox.lib.conversion import string_to_type
  8. from checkbox.properties import Path, String
  9. from checkbox.registries.command import CommandRegistry
  10. from checkbox.registries.data import DataRegistry
  11.  
  12. class SourceRegistry(DataRegistry):
  13.     
  14.     def items(self):
  15.         items = []
  16.         lines = []
  17.         id = None
  18.         depth = None
  19.         for line in self.split('\n'):
  20.             if not line:
  21.                 continue
  22.             
  23.             match = re.match('(\\s+(\\/)?)(.+)', line)
  24.             if not match:
  25.                 lines[-1] += line
  26.                 continue
  27.             
  28.             space = len(match.group(1).rstrip('/'))
  29.             if depth is None:
  30.                 depth = space
  31.             
  32.             if space > depth:
  33.                 lines.append(line)
  34.                 continue
  35.             if match.group(2) is not None:
  36.                 if id is not None:
  37.                     value = SourceRegistry('\n'.join(lines))
  38.                     lines = []
  39.                     items.append((id, value))
  40.                 
  41.                 id = match.group(3).split('/')[-1].rstrip(':')
  42.                 continue
  43.             (key, value) = match.group(3).split(' = ', 1)
  44.             if value == '(no value set)':
  45.                 value = None
  46.             else:
  47.                 match = re.match('\\[([^\\]]*)\\]', value)
  48.                 if match:
  49.                     list_string = match.group(1)
  50.                     if len(list_string):
  51.                         value = list_string.split(',')
  52.                     else:
  53.                         value = []
  54.                 else:
  55.                     value = string_to_type(value)
  56.             items.append((key, value))
  57.         
  58.         if lines:
  59.             value = SourceRegistry('\n'.join(lines))
  60.             items.append((id, value))
  61.         
  62.         return items
  63.  
  64.  
  65.  
  66. class GconfRegistry(CommandRegistry):
  67.     '''Registry for gconf information.
  68.  
  69.     Each item contained in this registry consists of the udi as key and
  70.     the corresponding device registry as value.
  71.     '''
  72.     source = Path(default = '~/.gconf')
  73.     command = String(default = 'gconftool-2 -R / --direct --config-source xml:readwrite:$source')
  74.     
  75.     def __init__(self, *args, **kwargs):
  76.         super(GconfRegistry, self).__init__(*args, **kwargs)
  77.         source = posixpath.expanduser(self.source)
  78.         self.command = self.command.replace('$source', source)
  79.  
  80.     
  81.     def items(self):
  82.         items = []
  83.         key = None
  84.         lines = []
  85.         for line in self.split('\n'):
  86.             if line.startswith(' /'):
  87.                 if lines:
  88.                     value = SourceRegistry('\n'.join(lines))
  89.                     items.append((key, value))
  90.                 
  91.                 key = line.strip().lstrip('/').rstrip(':')
  92.                 continue
  93.             if line:
  94.                 lines.append(line)
  95.                 continue
  96.         
  97.         if lines:
  98.             value = SourceRegistry('\n'.join(lines))
  99.             items.append((key, value))
  100.         
  101.         return items
  102.  
  103.     items = cache(items)
  104.  
  105. factory = GconfRegistry
  106.